package 剑指offer.数组中重复的数字03;

import java.sql.Time;
import java.util.concurrent.TimeUnit;

/**
 * 作者：derrick_sun
 * 链接：https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/solution/yuan-di-zhi-huan-shi-jian-kong-jian-100-by-derrick/
 * 来源：力扣（LeetCode）
 * 著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。
 */
class Solution3 {
    public static void main(String[] args) {
        Solution3 a = new Solution3();
        int[] nums = new int[]{2, 3, 1, 0, 2, 5, 3};
        System.out.println(a.findRepeatNumber(nums));
    }
        public int findRepeatNumber(int[] nums) {
            int i = 0;
            while(i < nums.length) {
                if(nums[i] == i) {
                    i++;
                    continue;
                }
                if(nums[nums[i]] == nums[i]) return nums[i];
                int tmp = nums[i];
                nums[i] = nums[tmp];
                nums[tmp] = tmp;
            }
            return -1;

        }
    }

